<template>
  <div>
    <head-top routerName="orderManagement" :blackRadian="false"></head-top>
    <div class="black-wrap">
      <div
        class="noCity"
        v-if="['0', '1', '2', '3'].indexOf(cityLeader) !== -1"
      >
        <div class="name">城市盟主</div>
        <div class="label">
          <template v-if="cityLeader === '0'"
            >目前还达不到升级城市盟主的标准
          </template>
          <template v-else> 您目前还不是城市盟主 </template>
        </div>
        <div
          class="button"
          v-if="cityLeader === '1'"
          @click="$refs.city.open = true"
        >
          申请
        </div>
        <div class="submitted" v-if="cityLeader === '2'">
          您已提交，请等待管理员联系您
        </div>
        <div class="submitted" v-else-if="cityLeader === '3'">申请已拒绝</div>
      </div>
      <div class="cityLeader" v-else>
        <div class="name">城市盟主</div>
        <router-link :to="{ name: 'IncomeDetails' }">
          <div class="right">收益明细<van-icon name="arrow" /></div>
        </router-link>
        <div class="address-info">
          <div class="label">您当前是</div>
          <div class="address">广东省 深圳市</div>
        </div>
        <ul>
          <li>
            <div class="label">总分红(元宝)</div>
            <div class="data">
              {{ "0.00" | formatFront
              }}<span class="decimal">{{ "0.00" | formatAfter }}</span>
            </div>
          </li>
          <li>
            <div class="label">昨日分红(元宝)</div>
            <div class="data">
              {{ "0.00" | formatFront
              }}<span class="decimal">{{ "0.00" | formatAfter }}</span>
            </div>
          </li>
          <li>
            <div class="label">用户数</div>
            <div class="data">621400</div>
          </li>
        </ul>
      </div>
    </div>
    <div class="content-wrap">
      <div class="title">城市盟主介绍</div>
      <div class="introduce">
        <p>1.VIP用户可申请。</p>
        <p>2.可获得本区域内交易手续费20%分红（以元宝形式发放）。</p>
        <p>3.可获得区域内，广告代理权。</p>
        <p>4.区域内，兑换商品及兑换ADWT手续费20%分红。</p>
      </div>
      <div class="footer" v-if="cityLeader === 2">
        <div class="button">广告管理</div>
        <div class="button black">发布广告</div>
      </div>
    </div>
    <city-user ref="city" @load="load"></city-user>
  </div>
</template>
<script>
import HeadTop from "@/components/head";
import { Icon } from "vant";
import { getCityUser, cityUserData } from "@/api/cityLeader";
export default {
  components: {
    HeadTop,
    [Icon.name]: Icon,
    cityUser: (resolve) => require(["./cityUser"], resolve),
  },
  data() {
    return {
      cityLeader: "",
    };
  },
  filters: {
    formatFront(text) {
      return text.substring(0, text.indexOf("."));
    },
    formatAfter(text) {
      return text.substr(text.lastIndexOf("."));
    },
  },
  created() {
    this.getStatus();
  },
  methods: {
    getStatus() {
      getCityUser({}).then((res) => {
        this.cityLeader = res.data.resultData.cityUser;
        if (this.cityLeader === "4") {
          cityUserData({}).then((res) => {
            console.log(res);
          });
        }
      });
    },
    load() {
      this.getStatus();
    },
  },
};
</script>
<style lang="less" scoped>
.black-wrap {
  height: 145px;
  padding: 0 17px;
  background: #333333;
  .name {
    padding-top: 9px;
    height: 16px;
    font-size: 16px;
    font-weight: 500;
    color: #f1c177;
    line-height: 16px;
  }
  .noCity {
    .label {
      padding: 14px 0 35px 0;
      height: 20px;
      font-size: 20px;
      font-weight: 600;
      color: #ffffff;
      line-height: 20px;
    }
    .button {
      width: 90px;
      height: 34px;
      line-height: 34px;
      text-align: center;
      font-size: 14px;
      font-weight: 400;
      color: #ffffff;
      background: #f1c177;
      border-radius: 17px;
    }
    .submitted {
      height: 20px;
      font-size: 14px;
      font-weight: 400;
      color: #f1c177;
      line-height: 20px;
    }
  }
  .cityLeader {
    position: relative;
    .right {
      position: absolute;
      top: 12px;
      right: 0;
      height: 11px;
      font-size: 11px;
      font-weight: 300;
      color: #eeeeee;
      line-height: 11px;
      display: flex;
      align-items: center;
    }
    .address-info {
      padding-top: 18px;
      .label {
        height: 11px;
        font-size: 11px;
        font-weight: 300;
        color: #999999;
        line-height: 11px;
      }
      .address {
        padding-top: 6px;
        height: 20px;
        font-size: 20px;
        font-weight: 600;
        color: #ffffff;
        line-height: 20px;
      }
    }
    ul {
      margin-top: 25px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      li {
        .label {
          height: 11px;
          font-size: 11px;
          font-weight: 300;
          color: #999999;
          line-height: 11px;
        }
        .data {
          margin-top: 8px;
          height: 12px;
          font-size: 16px;
          font-weight: bold;
          color: #ededed;
          line-height: 12px;
          span {
            font-size: 12px;
          }
        }
      }
    }
  }
}
.content-wrap {
  .title {
    margin: 23px 0 11px 0;
    display: inline-block;
    position: relative;
    height: 16px;
    padding: 0 2px;
    font-size: 14px;
    font-weight: 500;
    color: #333333;
    line-height: 14px;
    z-index: 1;
    &:after {
      position: absolute;
      content: "";
      bottom: 0;
      left: 0;
      height: 9px;
      width: 100%;
      background: #f1c177;
      opacity: 0.4;
      z-index: -1;
    }
  }
  .introduce {
    p {
      padding: 0 0 4px 0;
      margin: 0;
      height: 16px;
      font-size: 11px;
      font-weight: 400;
      color: #666660;
      line-height: 16px;
    }
  }
  .footer {
    position: relative;
    margin-top: 224px;
    display: flex;
    padding: 0 17px;
    justify-content: space-between;
    .button {
      width: 138px;
      height: 40px;
      text-align: center;
      font-size: 14px;
      font-weight: 600;
      color: #333333;
      line-height: 40px;
      border-radius: 22px;
      border: 1px solid #333333;
      &.black {
        color: #ffffff;
        background: #333333;
      }
    }
  }
}
</style>